<template>
  <BasicModal
    @register="register"
    title="请给出最终评分和评分依据"
    :okButtonProps="{ disabled: false }"
    @ok="upTimeLast"
  >
    <div style="margin-bottom: 25px; margin-left: 30px">
      评分状态
      <RadioGroup v-model:value="value2" style="margin-left: 10px" button-style="solid">
        <RadioButton value="10">未完成</RadioButton>
        <RadioButton value="20">进行中</RadioButton>
        <RadioButton value="30">已完成</RadioButton>
      </RadioGroup>
    </div>
    <div style="margin-bottom: 25px; margin-left: 30px; margin-top: 10px">
      最终评分
      <!-- :disabled="pinweifenshu.value == null" -->
      <a-input v-model:value="pinweifenshu" style="width: 200px; margin-left: 5px" />
    </div>
    <div style="margin-bottom: 25px; margin-left: 30px">
      评分依据
      <a-textarea
        v-model:value="pinweifenshuneirong"
        style="width: 380px; margin-left: 5px"
        :auto-size="{ minRows: 2, maxRows: 6 }"
      />
    </div>
  </BasicModal>
</template>
<script lang="ts" setup>
  import { ref } from 'vue';
  import { BasicModal, useModalInner } from '/@/components/Modal';
  import { Radio } from 'ant-design-vue';
  import { taskInterimMark, taskInterimMarkPUT } from '/@/api/basic/import/index';
  import { useMessage } from '/@/hooks/web/useMessage';
  const RadioGroup = Radio.Group;
  const RadioButton = Radio.Button;
  // components: { TimeRangePicker: TimePicker.TimeRangePicker}
  const { createMessage } = useMessage();
  let pinweifenshuneirong: any = ref();
  let pinweifenshu: any = ref();
  let record: any = ref();
  let results: any = ref();
  let yijuNum: any = ref();
  const value2 = ref<string>('10');
  const emit = defineEmits(['success', 'register']);
  const [register, { closeModal }] = useModalInner((data) => {
    // 赋值
    record.value = { ...data?.detailResule };
    results.value = { ...data?.results };
    yijuNum.value = record.value.targetScore;
    // console.log(yijuNum, '4444444');
    // console.log(data, '6666');
    if (record.value.markResultVOList) {
      for (var i = 0; i < record.value.markResultVOList.length; i++) {
        if (!record.value.markResultVOList[i].isDefault) {
          if (record.value.markResultVOList[i].score !== undefined) {
            pinweifenshu.value = record.value.markResultVOList[i].score;
            pinweifenshuneirong.value = record.value.markResultVOList[i].remarks;
            value2.value = record.value.markResultVOList[i].targetState;
          }
        }
      }
    }
  });
  async function upTimeLast() {
    if (pinweifenshu.value !== undefined && pinweifenshuneirong.value !== undefined) {
      if (pinweifenshu.value > record.value.targetScore) {
        createMessage.error(`评分不能大于项目分值，请重新填写`);
      } else {
        if (record.value.markResultVOList.length !== 0) {
          for (var i = 0; i < record.value.markResultVOList.length; i++) {
            if (!record.value.markResultVOList[i].isDefault) {
              if (record.value.markResultVOList[i].score !== undefined) {
                const arrchage = {
                  targetId: record.value.id,
                  score: pinweifenshu.value,
                  remarks: pinweifenshuneirong.value,
                  otherId: results.value.tenantId,
                  targetState: value2.value,
                  id: record.value.markResultVOList[i].id,
                };
                // console.log(arrchage, '222222222222');
                await taskInterimMarkPUT(arrchage);
                emit('success');
              }
            } else {
              const arr = {
                targetId: record.value.id,
                score: pinweifenshu.value,
                remarks: pinweifenshuneirong.value,
                otherId: results.value.tenantId,
                targetState: value2.value,
              };
              await taskInterimMark(arr);
              emit('success');
            }
          }
        } else {
          const arr = {
            targetId: record.value.id,
            score: pinweifenshu.value,
            remarks: pinweifenshuneirong.value,
            otherId: results.value.tenantId,
            targetState: value2.value,
          };
          await taskInterimMark(arr);
          emit('success');
        }
        closeModal();
        pinweifenshuneirong.value = '';
        pinweifenshu.value = '';
        value2.value = '10';
      }
    } else {
      createMessage.error(`评分或评分依据不能为空`);
    }
  }
</script>
